clear all
set more off
set type double, perm
capture log close

global d = 0

if $d == 0 { 
global topdir "YOUR DIRECTORY"
global datadir "${topdir}/data"
global outdir "${topdir}/output"
cd "${outdir}"
}

use "${datadir}/nlsy_final.dta", clear

log using nlsy_analysis.log, replace



/*  ------------------------------------------------------------------------  */
/*                           Table 1                                          */
/*  ------------------------------------------------------------------------  */

// by cohort
foreach g in WM WW {
	eststo `g'79: regress ln_wage aafqt [w=weight] if sample==0 & group2=="`g'", robust
	eststo `g'97: regress ln_wage aafqt [w=weight] if sample==1 & group2=="`g'", robust
}
esttab WM79 WM97 WW79 WW97 using "Table1A.csv", replace   ///
compress nonumbers mtitle label stats(N r2, labels("Obs" "R-Square")) ///
collabels(none) nonumbers nogaps drop(_cons) ///
star(* 0.10 ** 0.05 *** 0.01) se bracket posthead("Panel A: Univariate Regression")

foreach g in WM WW {
	eststo `g'79: regress ln_wage aafqt soc_nlsy2_std noncog_std [w=weight] if sample==0 & group2=="`g'", robust
	eststo `g'97: regress ln_wage aafqt soc_nlsy2_std noncog_std [w=weight] if sample==1 & group2=="`g'", robust
}
esttab WM79 WM97 WW79 WW97 using "Table1A.csv", append   ///
compress nonumbers mtitle label stats(N r2, labels("Obs" "R-Square")) ///
collabels(none) mlabels(none) nonumbers nogaps drop(_cons) ///
star(* 0.10 ** 0.05 *** 0.01) se bracket posthead("Panel B: Control for Non-cognitive & Social Skills")

foreach g in WM WW {
	eststo `g'79: regress ln_wage aafqt educ [w=weight] if sample==0 & group2=="`g'", robust
	eststo `g'97: regress ln_wage aafqt educ [w=weight] if sample==1 & group2=="`g'", robust
}
esttab WM79 WM97 WW79 WW97 using "Table1A.csv", append   ///
compress nonumbers mtitle label stats(N r2, labels("Obs" "R-Square")) ///
collabels(none) mlabels(none) nonumbers nogaps drop(_cons) ///
star(* 0.10 ** 0.05 *** 0.01) se bracket posthead("Panel C: Control for Education")

foreach g in WM WW {
	eststo `g'79: regress ln_wage aafqt educ soc_nlsy2_std noncog_std [w=weight] if sample==0 & group2=="`g'", robust
	eststo `g'97: regress ln_wage aafqt educ soc_nlsy2_std noncog_std [w=weight] if sample==1 & group2=="`g'", robust
}
esttab WM79 WM97 WW79 WW97 using "Table1A.csv", append   ///
compress nonumbers mtitle label stats(N r2, labels("Obs" "R-Square")) ///
collabels(none) mlabels(none) nonumbers nogaps drop(_cons) ///
star(* 0.10 ** 0.05 *** 0.01) se bracket posthead("Panel D: Control for Non-cognitive & Social Skills & Education")


// interaction
foreach g in WM WW {
	eststo `g': regress ln_wage aafqt aafqt_sample sample [w=weight] if group2=="`g'", robust
}
esttab WM WW using "Table1B.csv", replace   ///
compress nonumbers mtitle label stats(N r2, labels("Obs" "R-Square")) ///
collabels(none) nonumbers nogaps drop(_cons sample) ///
star(* 0.10 ** 0.05 *** 0.01) se bracket posthead("Panel A: Univariate Regression")

foreach g in WM WW {
	eststo `g': regress ln_wage aafqt aafqt_sample sample soc_nlsy2_std soc_nlsy2_std_sample noncog_std noncog_std_sample [w=weight] if group2=="`g'", robust
}
esttab WM WW using "Table1B.csv", append   ///
compress nonumbers mtitle label stats(N r2, labels("Obs" "R-Square")) ///
collabels(none) mlabels(none) nonumbers nogaps drop(_cons sample) ///
star(* 0.10 ** 0.05 *** 0.01) se bracket posthead("Panel B: Control for Non-cognitive & Social Skills")

foreach g in WM WW {
	eststo `g': regress ln_wage aafqt aafqt_sample sample educ educ_sample [w=weight] if group2=="`g'", robust
}
esttab WM WW using "Table1B.csv", append   ///
compress nonumbers mtitle label stats(N r2, labels("Obs" "R-Square")) ///
collabels(none) mlabels(none) nonumbers nogaps drop(_cons sample) ///
star(* 0.10 ** 0.05 *** 0.01) se bracket posthead("Panel C: Control for Education")

foreach g in WM WW {
	eststo `g': regress ln_wage aafqt aafqt_sample sample educ educ_sample soc_nlsy2_std soc_nlsy2_std_sample noncog_std noncog_std_sample [w=weight] if group2=="`g'", robust
}
esttab WM WW using "Table1B.csv", append   ///
compress nonumbers mtitle label stats(N r2, labels("Obs" "R-Square")) ///
collabels(none) mlabels(none) nonumbers nogaps drop(_cons sample) ///
star(* 0.10 ** 0.05 *** 0.01) se bracket posthead("Panel D: Control for Non-cognitive & Social Skills & Education")


/*  ------------------------------------------------------------------------  */
/*                           Table 2                                          */
/*  ------------------------------------------------------------------------  */

tab aafqt sample [w=weight] if female==0 & race==3, chi
tab aafqt sample [w=weight] if female==1 & race==3, chi
est clear
estpost tabstat aafqt [w=weight], by(group) stat(mean sd skewness kurtosis p1 p5 p10 p25 p50 p75 p90 p95 p99) columns(statistics) listwise
esttab using "Table2.csv", replace cells("mean sd skewness kurtosis p1 p5 p10 p25 p50 p75 p90 p95 p99") nonumber 


	

/*  ------------------------------------------------------------------------  */
/*                           Table A1                                         */
/*  ------------------------------------------------------------------------  */

est clear
estpost tabstat avg_age educ_hs educ_sc educ_co aafqt hgc_mom bothparents_age14 [w=weight] if race==3, by(group)
esttab using "TableA1.csv", replace nonumber 


/*  ------------------------------------------------------------------------  */
/*                           Table A2                                         */
/*  ------------------------------------------------------------------------  */

tab ar_altonji sample [w=weight] if female==0 & race==3, chi
tab ar_altonji sample [w=weight] if female==1 & race==3, chi
est clear
estpost tabstat ar_altonji [w=weight], by(group) stat(mean sd skewness kurtosis p1 p5 p10 p25 p50 p75 p90 p95 p99) columns(statistics) listwise
esttab using "TableA2.csv", replace cells("mean sd skewness kurtosis p1 p5 p10 p25 p50 p75 p90 p95 p99") nonumber 
	
	
/*  ------------------------------------------------------------------------  */
/*                           Table E1                                         */
/*  ------------------------------------------------------------------------  */

foreach g in WM BM HM WW BW HW {
	eststo `g': regress ln_wage aafqt aafqt_sample sample [w=weight] if group2=="`g'", robust
}
esttab WM WW BM BW HM HW using "TableE1.csv", replace   ///
compress nonumbers mtitle label stats(N r2, labels("Obs" "R-Square")) ///
collabels(none) nonumbers nogaps drop(_cons sample) ///
star(* 0.10 ** 0.05 *** 0.01) se bracket posthead("Panel A: Univariate Regression")

foreach g in WM BM HM WW BW HW {
	eststo `g': regress ln_wage aafqt aafqt_sample sample soc_nlsy2_std soc_nlsy2_std_sample noncog_std noncog_std_sample [w=weight] if group2=="`g'", robust
}
esttab WM WW BM BW HM HW using "TableE1.csv", append   ///
compress nonumbers mtitle label stats(N r2, labels("Obs" "R-Square")) ///
collabels(none) mlabels(none) nonumbers nogaps drop(_cons sample) ///
star(* 0.10 ** 0.05 *** 0.01) se bracket posthead("Panel B: Control for Non-cognitive & Social Skills")


/*  ------------------------------------------------------------------------  */
/*                            Table H2                                        */
/*  ------------------------------------------------------------------------  */

foreach g in WM WW {
	eststo `g': regress ln_wage aafqt aafqt_sample sample [w=weight] if group2=="`g'", robust
}
esttab WM WW using "TableH2.csv", replace   ///
compress nonumbers mtitle label stats(N r2, labels("Obs" "R-Square")) ///
collabels(none) nonumbers nogaps drop(_cons sample) ///
star(* 0.10 ** 0.05 *** 0.01) se bracket posthead("Panel A: Baseline")

foreach g in WM WW {
	eststo `g': regress ln_wage aafqt aafqt_sample sample avg_age avg_age_sample sample [w=weight] if group2=="`g'", robust
}
esttab WM WW using "TableH2.csv", append   ///
compress nonumbers mtitle label stats(N r2, labels("Obs" "R-Square")) ///
collabels(none) nonumbers nogaps drop(_cons sample) ///
star(* 0.10 ** 0.05 *** 0.01) se bracket posthead("Panel B: Control for age")

foreach g in WM WW {
	eststo `g': regress ln_wage aafqt avg_age aafqt_avg_age aafqt_sample avg_age_sample aafqt_avg_age_sample sample [w=weight] if group2=="`g'", robust
}
esttab WM WW using "TableH2.csv", append   ///
compress nonumbers mtitle label stats(N r2, labels("Obs" "R-Square")) ///
collabels(none) nonumbers nogaps drop(_cons sample) ///
star(* 0.10 ** 0.05 *** 0.01) se bracket posthead("Panel C: Interact with age")


/*  ------------------------------------------------------------------------  */
/*                            Table H3                                        */
/*  ------------------------------------------------------------------------  */

foreach g in WM WW {
	eststo `g': regress ln_wage aafqt aafqt_sample sample [w=weight] if group2=="`g'", robust
}
esttab WM WW using "TableH3.csv", replace   ///
compress nonumbers mtitle label stats(N r2, labels("Obs" "R-Square")) ///
collabels(none) nonumbers nogaps drop(_cons sample) ///
star(* 0.10 ** 0.05 *** 0.01) se bracket posthead("Panel A: 25-39 (Baseline)")

foreach g in WM WW {
	eststo `g': regress ln_wage_noschl3133 aafqt aafqt_sample sample [w=weight] if group2=="`g'", robust
}
esttab WM WW using "TableH3.csv", append   ///
compress nonumbers mtitle label stats(N r2, labels("Obs" "R-Square")) ///
collabels(none) nonumbers nogaps drop(_cons sample) ///
star(* 0.10 ** 0.05 *** 0.01) se bracket posthead("Panel B: 31-33")


/*  ------------------------------------------------------------------------  */
/*                            Table G1                                        */
/*  ------------------------------------------------------------------------  */

foreach g in WM WW {
	eststo `g'79: regress ln_wage aafqt_belowp50 aafqt_abovep50 abovep50 [w=weight] if sample==0 & group2=="`g'", robust
	eststo `g'97: regress ln_wage aafqt_belowp50 aafqt_abovep50 abovep50 [w=weight] if sample==1 & group2=="`g'", robust
}
esttab WM79 WM97 WW79 WW97 using "TableG1.csv", replace   ///
compress nonumbers mtitle label stats(N r2, labels("Obs" "R-Square")) ///
collabels(none) nonumbers nogaps ///
star(* 0.10 ** 0.05 *** 0.01) se bracket posthead("Panel A: by median")

foreach g in WM WW {
	eststo `g'0: regress ln_wage aafqt aafqt_sample sample [w=weight] if abovep50==0 & group2=="`g'", robust
	eststo `g'1: regress ln_wage aafqt aafqt_sample sample [w=weight] if abovep50==1 & group2=="`g'", robust
}
esttab WM0 WW0 using "TableG1.csv", append   ///
compress nonumbers mtitle label stats(N r2, labels("Obs" "R-Square")) ///
collabels(none) nonumbers nogaps ///
star(* 0.10 ** 0.05 *** 0.01) se bracket posthead("Panel B: below p50")
esttab WM1 WW1 using "TableG1.csv", append   ///
compress nonumbers mtitle label stats(N r2, labels("Obs" "R-Square")) ///
collabels(none) nonumbers nogaps ///
star(* 0.10 ** 0.05 *** 0.01) se bracket posthead("Panel C: above p50")


/*  ------------------------------------------------------------------------  */
/*                            Figure 1                                        */
/*  ------------------------------------------------------------------------  */

sort sample group2 aafqt
by sample group2 aafqt: egen wt_groupsize = total(weight) // group size including sample weight
egen tag = tag(sample group2 aafqt)
by sample group2 aafqt: egen sum_y = total(ln_wage*weight)
gen wt_y = sum_y/wt_groupsize // weighted avg log wage

twoway (scatter wt_y aafqt if sample==0 & female==0 & race==3 & tag==1, msymbol(circle_hollow) msize(small)) ///
	(scatter wt_y aafqt if sample==1 & female==0 & race==3 & tag==1, msize(small)) ///
	(lfit wt_y aafqt if sample==0 & female==0 & race==3 & tag==1 [w=wt_groupsize], color(green)) ///
	(lfit wt_y aafqt if sample==1 & female==0 & race==3 & tag==1 [w=wt_groupsize], color(orange_red)), ///
	xsc(r(70 230)) xlabel(75(25)225) xtitle("AAFQT") ytitle("") ///
	scheme(s1color) legend(order(1 "NLSY-79" 2 "NLSY-97"))
graph save Figure1_WM, replace
graph export Figure1_WM.pdf, replace
graph export Figure1_WM.eps, replace

twoway (scatter wt_y aafqt if sample==0 & female==1 & race==3 & tag==1, msymbol(circle_hollow) msize(small)) ///
	(scatter wt_y aafqt if sample==1 & female==1 & race==3 & tag==1, msize(small)) ///
	(lfit wt_y aafqt if sample==0 & female==1 & race==3 & tag==1 [w=wt_groupsize], color(green)) ///
	(lfit wt_y aafqt if sample==1 & female==1 & race==3 & tag==1 [w=wt_groupsize], color(orange_red)), ///
	xsc(r(70 230)) xlabel(75(25)225) xtitle("AAFQT") ytitle("") ///
	scheme(s1color) legend(order(1 "NLSY-79" 2 "NLSY-97"))
graph save Figure1_WW, replace
graph export Figure1_WW.pdf, replace
graph export Figure1_WW.eps, replace

drop sum_y wt_y wt_groupsize tag



/*  ------------------------------------------------------------------------  */
/*                            Figure 2                                        */
/*  ------------------------------------------------------------------------  */

sum aafqt if sample==0 & female==0 & race==3 [w=weight], d
local mean79 = int(r(mean)*10)/10
local sd79 = int(r(sd)*10)/10
local skew79 = int(r(skewness)*100)/100
local p179 = int(r(p1))
local p579 = int(r(p5))
local p1079 = int(r(p10))
local p2579 = int(r(p25))
local median79 = int(r(p50))
local p7579 = int(r(p75))
local p9079 = int(r(p90))
sum aafqt if sample==1 & female==0 & race==3 [w=weight], d
local mean97 = int(r(mean)*10)/10
local sd97 = int(r(sd)*10)/10
local skew97 = int(r(skewness)*100)/100
local p197 = int(r(p1))
local p597 = int(r(p5))
local p1097 = int(r(p10))
local p2597 = int(r(p25))
local median97 = int(r(p50))
local p7597 = int(r(p75))
local p9097 = int(r(p90))

twoway (kdensity aafqt if sample==0 & female==0 & race==3 [w=weight], lpattern(_)) ///
		(kdensity aafqt if sample==1 & female==0 & race==3 [w=weight]), ///
		ylabel(0(0.004)0.016) xsc(r(70 230)) xlabel(75(25)225) xtitle("AAFQT") ytitle("Density") ///
		scheme(s1color) legend(order(1 "NLSY-79" 2 "NLSY-97")) ///
		note("  NLSY-79:   Mean = `mean79', SD = `sd79', Skewness = `skew79', p1 = `p179', p5 = `p579', p50 = `median79'" "  NLSY-97:   Mean = `mean97', SD = `sd97', Skewness = `skew97', p1 = `p197',   p5 = `p597', p50 = `median97'")
graph save Figure2_WM, replace
graph export Figure2_WM.pdf, replace
graph export Figure2_WM.eps, replace


sum aafqt if sample==0 & female==1 & race==3 [w=weight], d
local mean79 = int(r(mean)*10)/10
local sd79 = int(r(sd)*10)/10
local skew79 = int(r(skewness)*100)/100
local p179 = int(r(p1))
local p579 = int(r(p5))
local p1079 = int(r(p10))
local p2579 = int(r(p25))
local median79 = int(r(p50))
local p7579 = int(r(p75))
local p9079 = int(r(p90))
sum aafqt if sample==1 & female==1 & race==3 [w=weight], d
local mean97 = int(r(mean)*10)/10
local sd97 = int(r(sd)*10)/10
local skew97 = int(r(skewness)*100)/100
local p197 = int(r(p1))
local p597 = int(r(p5))
local p1097 = int(r(p10))
local p2597 = int(r(p25))
local median97 = int(r(p50))
local p7597 = int(r(p75))
local p9097 = int(r(p90))

twoway (kdensity aafqt if sample==0 & female==1 & race==3 [w=weight], lpattern(_)) ///
		(kdensity aafqt if sample==1 & female==1 & race==3 [w=weight]), ///
		ylabel(0(0.004)0.016) xsc(r(70 230)) xlabel(75(25)225) xtitle("AAFQT") ytitle("Density") ///
		scheme(s1color) legend(order(1 "NLSY-79" 2 "NLSY-97")) ///
		note("  NLSY-79:   Mean = `mean79', SD = `sd79', Skewness = `skew79', p1 = `p179', p5 = `p579', p50 = `median79'" "  NLSY-97:   Mean = `mean97', SD = `sd97',    Skewness = `skew97', p1 = `p197',   p5 = `p597', p50 = `median97'")
graph save Figure2_WW, replace
graph export Figure2_WW.pdf, replace
graph export Figure2_WW.eps, replace




/*  ------------------------------------------------------------------------  */
/*                           Figure A1                                        */
/*  ------------------------------------------------------------------------  */

sum res_aafqt if sample==0 & female==0 & race==3 [w=weight], d
local mean79 = int(r(mean)*10)/10
local sd79 = int(r(sd)*10)/10
local skew79 = int(r(skewness)*100)/100
local p179 = int(r(p1))
local p579 = int(r(p5))
local p1079 = int(r(p10))
local p2579 = int(r(p25))
local median79 = int(r(p50))
local p7579 = int(r(p75))
local p9079 = int(r(p90))
sum res_aafqt if sample==1 & female==0 & race==3 [w=weight], d
local mean97 = int(r(mean)*10)/10
local sd97 = int(r(sd)*10)/10
local skew97 = int(r(skewness)*100)/100
local p197 = int(r(p1))
local p597 = int(r(p5))
local p1097 = int(r(p10))
local p2597 = int(r(p25))
local median97 = int(r(p50))
local p7597 = int(r(p75))
local p9097 = int(r(p90))

twoway (kdensity res_aafqt if sample==0 & female==0 & race==3 [w=weight], lpattern(_)) ///
		(kdensity res_aafqt if sample==1 & female==0 & race==3 [w=weight]), ///
		xsc(r(70 230)) xlabel(75(25)225) ///
		xtitle("Residualized AAFQT (+Mean AAFQT)") ytitle("Density") ///
		scheme(s1color) legend(order(1 "NLSY-79" 2 "NLSY-97")) ///
		note("  NLSY-79:   Mean = `mean79', SD = `sd79', Skewness = `skew79', p1 = `p179', p5 = `p579', p50 = `median79'" "  NLSY-97:   Mean = `mean97', SD = `sd97', Skewness = `skew97', p1 = `p197',   p5 = `p597', p50 = `median97'")
graph save FigureA1_WM, replace
graph export FigureA1_WM.pdf, replace
graph export FigureA1_WM.eps, replace


sum res_aafqt if sample==0 & female==1 & race==3 [w=weight], d
local mean79 = int(r(mean)*10)/10
local sd79 = int(r(sd)*10)/10
local skew79 = int(r(skewness)*100)/100
local p179 = int(r(p1))
local p579 = int(r(p5))
local p1079 = int(r(p10))
local p2579 = int(r(p25))
local median79 = int(r(p50))
local p7579 = int(r(p75))
local p9079 = int(r(p90))
sum res_aafqt if sample==1 & female==1 & race==3 [w=weight], d
local mean97 = int(r(mean)*10)/10
local sd97 = int(r(sd)*10)/10
local skew97 = int(r(skewness)*100)/100
local p197 = int(r(p1))
local p597 = int(r(p5))
local p1097 = int(r(p10))
local p2597 = int(r(p25))
local median97 = int(r(p50))
local p7597 = int(r(p75))
local p9097 = int(r(p90))

twoway (kdensity res_aafqt if sample==0 & female==1 & race==3 [w=weight], lpattern(_)) ///
		(kdensity res_aafqt if sample==1 & female==1 & race==3 [w=weight]), ///
		xsc(r(70 230)) xlabel(75(25)225) ///
		xtitle("Residualized AAFQT (+Mean AAFQT)") ytitle("Density") ///
		scheme(s1color) legend(order(1 "NLSY-79" 2 "NLSY-97")) ///
		note("  NLSY-79:   Mean = `mean79', SD = `sd79', Skewness = `skew79', p1 = `p179', p5 = `p579', p50 = `median79'" "  NLSY-97:   Mean = `mean97', SD = `sd97',    Skewness = `skew97', p1 = `p197',   p5 = `p597', p50 = `median97'")
graph save FigureA1_WW, replace
graph export FigureA1_WW.pdf, replace
graph export FigureA1_WW.eps, replace



/*  ------------------------------------------------------------------------  */
/*                            Figure A2                                       */
/*  ------------------------------------------------------------------------  */

capture graph drop _all
twoway (kdensity ar_altonji if sample==0 & female==0 & race==3 [w=weight], lpattern(_)) ///
		(kdensity ar_altonji if sample==1 & female==0 & race==3 [w=weight]), ///
		 xsc(r(20 70)) xlabel(20(10)70) xtitle("Adjusted score") ytitle("Density") title("Arithmetic Reasoning") ///
		scheme(s1color) legend(order(1 "NLSY-79" 2 "NLSY-97")) name(g1)
twoway (kdensity wk_altonji if sample==0 & female==0 & race==3 [w=weight], lpattern(_)) ///
		(kdensity wk_altonji if sample==1 & female==0 & race==3 [w=weight]), ///
		 xsc(r(20 70)) xlabel(20(10)70) xtitle("Adjusted score") ytitle("Density") title("Word Knowledge") ///
		scheme(s1color) legend(order(1 "NLSY-79" 2 "NLSY-97")) name(g2)
twoway (kdensity pc_altonji if sample==0 & female==0 & race==3 [w=weight], lpattern(_)) ///
		(kdensity pc_altonji if sample==1 & female==0 & race==3 [w=weight]), ///
		 xsc(r(20 70)) xlabel(20(10)70) xtitle("Adjusted score") ytitle("Density") title("Paragraph Comprehension") ///
		scheme(s1color) legend(order(1 "NLSY-79" 2 "NLSY-97")) name(g3)
twoway (kdensity no_altonji if sample==0 & female==0 & race==3 [w=weight], lpattern(_)) ///
		(kdensity no_altonji if sample==1 & female==0 & race==3 [w=weight]), ///
		 xsc(r(20 70)) xlabel(20(10)70) xtitle("Adjusted score") ytitle("Density") title("Numerical Operation") ///
		scheme(s1color) legend(order(1 "NLSY-79" 2 "NLSY-97")) name(g4)		
grc1leg g1 g2 g3 g4, legendfrom(g1) col(2) scheme(s1color)
graph save FigureA2_WM, replace
graph export FigureA2_WM.pdf, replace
graph export FigureA2_WM.eps, replace

capture graph drop _all
twoway (kdensity ar_altonji if sample==0 & female==1 & race==3 [w=weight], lpattern(_)) ///
		(kdensity ar_altonji if sample==1 & female==1 & race==3 [w=weight]), ///
		 xsc(r(20 70)) xlabel(20(10)70) xtitle("Adjusted score") ytitle("Density") title("Arithmetic Reasoning") ///
		scheme(s1color) legend(order(1 "NLSY-79" 2 "NLSY-97")) name(g1)
twoway (kdensity wk_altonji if sample==0 & female==1 & race==3 [w=weight], lpattern(_)) ///
		(kdensity wk_altonji if sample==1 & female==1 & race==3 [w=weight]), ///
		 xsc(r(20 70)) xlabel(20(10)70) xtitle("Adjusted score") ytitle("Density") title("Word Knowledge") ///
		scheme(s1color) legend(order(1 "NLSY-79" 2 "NLSY-97")) name(g2)
twoway (kdensity pc_altonji if sample==0 & female==1 & race==3 [w=weight], lpattern(_)) ///
		(kdensity pc_altonji if sample==1 & female==1 & race==3 [w=weight]), ///
		 xsc(r(20 70)) xlabel(20(10)70) xtitle("Adjusted score") ytitle("Density") title("Paragraph Comprehension") ///
		scheme(s1color) legend(order(1 "NLSY-79" 2 "NLSY-97")) name(g3)
twoway (kdensity no_altonji if sample==0 & female==1 & race==3 [w=weight], lpattern(_)) ///
		(kdensity no_altonji if sample==1 & female==1 & race==3 [w=weight]), ///
		 xsc(r(20 70)) xlabel(20(10)70) xtitle("Adjusted score") ytitle("Density") title("Numerical Operation") ///
		scheme(s1color) legend(order(1 "NLSY-79" 2 "NLSY-97")) name(g4)		
grc1leg g1 g2 g3 g4, legendfrom(g1) col(2) scheme(s1color)
graph save FigureA2_WW, replace
graph export FigureA2_WW.pdf, replace
graph export FigureA2_WW.eps, replace




/*  ------------------------------------------------------------------------  */
/*                            Figure B1                                       */
/*  ------------------------------------------------------------------------  */

capture graph drop _all
twoway (kdensity ar if sample==0 & female==0 & race==3 [w=weight], lpattern(_)) (kdensity ar if sample==1 & female==0 & race==3 [w=weight]), ///
	scheme(s1color) legend(label(1 "NLSY-79") label(2 "NLSY-97")) ///
	title("Arithmetic Reasoning") xtitle("Theta") ytitle("Density") name(g1)
twoway (kdensity wk if sample==0 & female==0 & race==3 [w=weight], lpattern(_)) (kdensity wk if sample==1 & female==0 & race==3 [w=weight]), ///
	scheme(s1color) legend(label(1 "NLSY-79") label(2 "NLSY-97")) ///
	title("Word Knowledge") xtitle("Theta") ytitle("Density") name(g2)	
twoway (kdensity pc if sample==0 & female==0 & race==3 [w=weight], lpattern(_)) (kdensity pc if sample==1 & female==0 & race==3 [w=weight]), ///
	scheme(s1color) legend(label(1 "NLSY-79") label(2 "NLSY-97")) ///
	title("Paragraph Comprehension") xtitle("Theta") ytitle("Density") name(g3)
grc1leg g1 g2 g3, legendfrom(g1) col(2) scheme(s1color)
graph save FigureB1_WM, replace
graph export FigureB1_WM.pdf, replace
graph export FigureB1_WM.eps, replace

capture graph drop _all
twoway (kdensity ar if sample==0 & female==1 & race==3 [w=weight], lpattern(_)) (kdensity ar if sample==1 & female==1 & race==3 [w=weight]), ///
	scheme(s1color) legend(label(1 "NLSY-79") label(2 "NLSY-97")) ///
	title("Arithmetic Reasoning") xtitle("Theta") ytitle("Density") name(g1)
twoway (kdensity wk if sample==0 & female==1 & race==3 [w=weight], lpattern(_)) (kdensity wk if sample==1 & female==1 & race==3 [w=weight]), ///
	scheme(s1color) legend(label(1 "NLSY-79") label(2 "NLSY-97")) ///
	title("Word Knowledge") xtitle("Theta") ytitle("Density") name(g2)	
twoway (kdensity pc if sample==0 & female==1 & race==3 [w=weight], lpattern(_)) (kdensity pc if sample==1 & female==1 & race==3 [w=weight]), ///
	scheme(s1color) legend(label(1 "NLSY-79") label(2 "NLSY-97")) ///
	title("Paragraph Comprehension") xtitle("Theta") ytitle("Density") name(g3)
grc1leg g1 g2 g3, legendfrom(g1) col(2) scheme(s1color)
graph save FigureB1_WW, replace
graph export FigureB1_WW.pdf, replace
graph export FigureB1_WW.eps, replace



/*  ------------------------------------------------------------------------  */
/*                            Figure B2                                       */
/*  ------------------------------------------------------------------------  */

capture graph drop _all
twoway (scatter ar_se ar if sample==0 & female==0 & race==3, msize(small) ms(circle_hollow)) (scatter ar_se ar if sample==1 & female==0 & race==3, msize(small) ms(circle_hollow)), ///
	scheme(s1color) legend(label(1 "NLSY-79") label(2 "NLSY-97")) ///
	title("Arithmetic Reasoning") xtitle("Theta") ytitle("S.E. of Theta") name(g1)
twoway (scatter wk_se wk if sample==0 & female==0 & race==3, msize(small) ms(circle_hollow)) (scatter wk_se wk if sample==1 & female==0 & race==3, msize(small) ms(circle_hollow)), ///
	scheme(s1color) legend(label(1 "NLSY-79") label(2 "NLSY-97")) ///
	title("Word Knowledge") xtitle("Theta") ytitle("S.E. of Theta") name(g2)
twoway (scatter pc_se pc if sample==0 & female==0 & race==3, msize(small) msymbol(circle_hollow)) (scatter pc_se pc if sample==1 & female==0 & race==3, msize(small) ms(circle_hollow)), ///
	scheme(s1color) legend(label(1 "NLSY-79") label(2 "NLSY-97")) ///
	title("Paragraph Comprehension") xtitle("Theta") ytitle("S.E. of Theta") name(g3)
grc1leg g1 g2 g3, legendfrom(g1) col(2) scheme(s1color)
graph save FigureB2_WM, replace
graph export FigureB2_WM.pdf, replace
graph export FigureB2_WM.eps, replace


capture graph drop _all
twoway (scatter ar_se ar if sample==0 & female==1 & race==3, msize(small) ms(circle_hollow)) (scatter ar_se ar if sample==1 & female==1 & race==3, msize(small) ms(circle_hollow)), ///
	scheme(s1color) legend(label(1 "NLSY-79") label(2 "NLSY-97")) ///
	title("Arithmetic Reasoning") xtitle("Theta") ytitle("S.E. of Theta") name(g1)
twoway (scatter wk_se wk if sample==0 & female==1 & race==3, msize(small) ms(circle_hollow)) (scatter wk_se wk if sample==1 & female==1 & race==3, msize(small) ms(circle_hollow)), ///
	scheme(s1color) legend(label(1 "NLSY-79") label(2 "NLSY-97")) ///
	title("Word Knowledge") xtitle("Theta") ytitle("S.E. of Theta") name(g2)
twoway (scatter pc_se pc if sample==0 & female==1 & race==3, msize(small) msymbol(circle_hollow)) (scatter pc_se pc if sample==1 & female==1 & race==3, msize(small) ms(circle_hollow)), ///
	scheme(s1color) legend(label(1 "NLSY-79") label(2 "NLSY-97")) ///
	title("Paragraph Comprehension") xtitle("Theta") ytitle("S.E. of Theta") name(g3)
grc1leg g1 g2 g3, legendfrom(g1) col(2) scheme(s1color)
graph save FigureB2_WW, replace
graph export FigureB2_WW.pdf, replace
graph export FigureB2_WW.eps, replace



/*  ------------------------------------------------------------------------  */
/*                            Figure E1                                       */
/*  ------------------------------------------------------------------------  */

capture graph drop _all
twoway (kdensity aafqt if sample==0 & female==0 & race==3 [w=weight], lpattern(_)) ///
		(kdensity aafqt if sample==1 & female==0 & race==3 [w=weight]), ///
		ylabel(0(0.004)0.016) xsc(r(70 230)) xlabel(75(25)225) xtitle("AAFQT") ytitle("Density") title("White Non-Hispanic Men") ///
		scheme(s1color) legend(order(1 "NLSY-79" 2 "NLSY-97")) aspectratio(.8) name(g1)
twoway (kdensity aafqt if sample==0 & female==1 & race==3 [w=weight], lpattern(_)) ///
		(kdensity aafqt if sample==1 & female==1 & race==3 [w=weight]), ///
		ylabel(0(0.004)0.016) xsc(r(70 230)) xlabel(75(25)225) xtitle("AAFQT") ytitle("Density") title("White Non-Hispanic Women") ///
		scheme(s1color) legend(order(1 "NLSY-79" 2 "NLSY-97")) aspectratio(.8) name(g2)
twoway (kdensity aafqt if sample==0 & female==0 & race==2 [w=weight], lpattern(_)) ///
		(kdensity aafqt if sample==1 & female==0 & race==2 [w=weight]), ///
		ylabel(0(0.004)0.016) xsc(r(70 230)) xlabel(75(25)225) xtitle("AAFQT") ytitle("Density") title("Black Men") ///
		scheme(s1color) legend(order(1 "NLSY-79" 2 "NLSY-97")) aspectratio(.8) name(g3)
twoway (kdensity aafqt if sample==0 & female==1 & race==2 [w=weight], lpattern(_)) ///
		(kdensity aafqt if sample==1 & female==1 & race==2 [w=weight]), ///
		ylabel(0(0.004)0.016) xsc(r(70 230)) xlabel(75(25)225) xtitle("AAFQT") ytitle("Density") title("Black Women") ///
		scheme(s1color) legend(order(1 "NLSY-79" 2 "NLSY-97")) aspectratio(.8) name(g4)		
twoway (kdensity aafqt if sample==0 & female==0 & race==1 [w=weight], lpattern(_)) ///
		(kdensity aafqt if sample==1 & female==0 & race==1 [w=weight]), ///
		ylabel(0(0.004)0.016) xsc(r(70 230)) xlabel(75(25)225) xtitle("AAFQT") ytitle("Density") title("Hispanic Men") ///
		scheme(s1color) legend(order(1 "NLSY-79" 2 "NLSY-97")) aspectratio(.8) name(g5)
twoway (kdensity aafqt if sample==0 & female==1 & race==1 [w=weight], lpattern(_)) ///
		(kdensity aafqt if sample==1 & female==1 & race==1 [w=weight]), ///
		ylabel(0(0.004)0.016) xsc(r(70 230)) xlabel(75(25)225) xtitle("AAFQT") ytitle("Density") title("Hispanic Women") ///
		scheme(s1color) legend(order(1 "NLSY-79" 2 "NLSY-97")) aspectratio(.8) name(g6)				
		
grc1leg g1 g3 g5 g2 g4 g6, legendfrom(g1) col(3) scheme(s1color)
graph save FigureE1, replace
graph export FigureE1.pdf, replace
graph export FigureE1.eps, replace





log close

exit

